package com.bfsuol.bfsuolframework.core.spring;

import org.apache.log4j.Logger;


public class QueryParamAccessor {//implements PropertyAccessor{
	
	protected final Logger logger = Logger.getLogger(getClass());
	
	public QueryParamAccessor(){
		if(logger.isDebugEnabled()){
			logger.debug("QueryAccessor new");
		}
	}
	/*
	@SuppressWarnings("unchecked")
	public Object getProperty(Map context, Object target, Object name)
			throws OgnlException {
		QueryParam query = (QueryParam)target;
		
		String key = convertString(name);
		if(key.equals("order")) {
            return query.getOrder().getField();
        }
		if(key.equals("orderDir")) {
			return query.getOrderDir();
        }
		
		if(key.equals("querySize")) {
            return query.getFixedQuerys().size();
        }
        if(key.equals("queryKeys")) {
           return query.getQueryKeys();
        }
        
        if(key.equals("querys")) {
            return query.getQuerys();
        }
        
        return query.getString(key, "");
        
	}

	@SuppressWarnings("unchecked")
	public void setProperty(Map context, Object target, Object name, Object value)
			throws OgnlException {
		
		QueryParam query = (QueryParam)target;
		
		String key = convertString(name);
		String val = convertString(value);
		if(key == null || key.equals("") || val == null || val.equals("")){
			return;
		}
		if(key.equals("order")) {
            query.setOrder(val);
        }
		if(key.equals("orderDir")) {
			query.setOrderDir(val);
        }
		
		query.addQuery(key, val, true);
		
	}
	
	public String getSourceAccessor(OgnlContext arg0, Object arg1, Object arg2) {
		return null;
	}

	public String getSourceSetter(OgnlContext arg0, Object arg1, Object arg2) {
		return null;
	}
	
	private String convertString(Object value){
		if(value == null){
			return null;
		}
		String result = null;
		if(value.getClass().getSimpleName().equals("String") ){
			result = (String)value;
		}else if(value.getClass().getSimpleName().equals("String[]")){
			String[] array = (String[])value;
			if(array.length>0){
				result = array[0];
			}
		}
		
		return result == null ? null : result.trim();
	}
	*/
}
